/**
 * Project Name:JavaBaseReview
 * Package Name:com.xuwei.ext.netty.example
 * author:David
 * Date:2016年6月17日上午9:40:41
 * Copyright (c) 2016, xw123box@126.com All Rights Reserved.
 *
 */
package com.xuwei.ext.netty.example;

import java.util.Date;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @author David
 * @since 2016年6月17日 上午9:40:41
 * @version 
 * @since JDK 1.6
 */
public class TimeClientHandler extends ChannelInboundHandlerAdapter {

	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg)
			throws Exception {
		ByteBuf m = (ByteBuf)msg;
		try {
			long currentTimeMillis = (m.readUnsignedInt()-220899900L)*1000L;
			System.out.println(new Date(currentTimeMillis));
			ctx.close();
		} finally {
			m.release();
		}
	}
	
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
			throws Exception {
		cause.printStackTrace();
		ctx.close();
	}

}
